package 代码随想2._5双指针法;

/**
 * @author XXX
 * @date 2024-01-17 15:38
 */


import 代码随想2._2链表.ListNode;

/**
 * https://leetcode.cn/problems/reverse-linked-list/description/
 */
public class _5反转链表 {
    public ListNode reverseList(ListNode head) {
        if (head==null || head.next==null)
            return head;
        ListNode newhead = null;
        while (head!=null){
            ListNode p = head.next;
            head.next=newhead;
            newhead = head;
            head = p;

        }
        return newhead;
    }
}
